USE [influenza]
GO

/****** Object:  StoredProcedure [dbo].[SP_RecAuxLabRes]    Script Date: 03/08/2010 13:12:37 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



ALTER PROCEDURE [dbo].[SP_RecAuxLabRes]
@param varchar(1000)
as
Begin
declare 
 @qry varchar(8000),
 @id_registro varchar(5),
 @id_muestras varchar(10)
 
 set @id_registro= dbo.fnSplit(@param,'|',1);
 set @id_muestras= dbo.fnSplit(@param,'|',2);
 

set @qry='select distinct a.nTecnica,a.nResultado, b.id_lab_Estudio as nEstudio,c.id_laboratorio as nUnidad, 
convert(varchar(10),a.fResultado,103) as fResultado, 
nProc,id_resultado,id_dat_registro,CONVERT(varchar(10),fTermino,103) as fTermino,id_resultado as id_auxLabRes
from aux_laboratorio_res a
left join cat_AdminLab b on(b.id_lab_tecnica=a.nTecnica and b.id_lab_resultado=a.nResultado and a.nProc=b.id_lab_proc) 
inner join dat_laboratorio c on(c.id_principal=a.id_dat_laboratorio)
left join dat_registro d on (d.id_principal = c.id_registro)
inner join aux_muestras e on (d.id_principal = e.id_principal and c.nTipomuestra=e.nTipomuestra)
where a.id_dat_registro='+@id_registro+' and id_muestras='+@id_muestras
 exec (@qry)

End
GO

